﻿using SWENAssignment.Sophia.Classes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SWENAssignment.Sophia
{
    public partial class addRoomReservation1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            lblCustomerID.Text = (string)Session["customerID"];
            lblRoomNum.Text = Request.QueryString["roomNum"];
        }

        protected void btnNext_Click(object sender, EventArgs e)
        {
            string r_reservationID = tbxReservationID.Text;
            bool r = DBmanager.ReservationIDIsExist(r_reservationID);
            if (r == true)
            {
                lblStatus.Text = "Reservation ID already exist. Please re-enter another Reservation ID!";
            }
            else
            {
                string r_customerID = lblCustomerID.Text;
                int r_numOfAdults = Convert.ToInt32(ddlNumOfAdults.SelectedValue);
                int r_numOfChildren = Convert.ToInt32(ddlNumOfChildren.SelectedValue);
                string r_preferredRoomType = ddlPrefRoomType.SelectedValue;
                string r_preferredBedType = ddlPrefBedType.SelectedValue;
                string r_smokingOrNot = ddlSmokingOrNot.SelectedValue;
                string r_roomNumber = lblRoomNum.Text;
                string r_reservationStatus = "NotArrived";

                roomReservation newReservation = new roomReservation(r_reservationID, r_customerID, r_numOfAdults, r_numOfChildren, r_preferredRoomType, r_preferredBedType, r_smokingOrNot, r_roomNumber, r_reservationStatus);
                if (DBmanager.insertRoomReservation(newReservation) == 1)
                {
                    DBmanager.UpdateRoomStatus(lblRoomNum.Text, "booked", tbxReservationID.Text);
                    Session["reservationID"] = r_reservationID;
                    string querystring = "roomNum=" + lblRoomNum.Text + "&roomReservation=" + tbxReservationID.Text;
                    Server.Transfer("~/Sophia/addRoomReservationSuccessfully.aspx?" + querystring);
                }
                else
                {
                    lblStatus2.Text = "New Room reservation cannot be added!";
                }


            }
        }
    }
}